home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7616 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  64 lines

  1. Path: lowell.bellcore.com!usenet
  2. From: Rick Porter <fdpo@thumper.bellcore.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: nested templates
  5. Date: 23 Feb 1996 16:46:48 GMT
  6. Organization: Bell Communications Research (Bellcore)
  7. Message-ID: <4gkr1o$bg6@lowell.bellcore.com>
  8. NNTP-Posting-Host: bambam.bellcore.com
  9.  
  10. I am having trouble using nested templates.  Can anyone tell me how to
  11. make this work, or suggest a workaround?  I've reduced the problem to
  12. the following simple example. 
  13.  
  14. ----------------------------------------------------- 
  15. file a.h: 
  16.  
  17. #ifndef A_H 
  18. #define A_H 
  19.  
  20. template<class T> 
  21. class B { 
  22.     T b; 
  23. }; 
  24.  
  25. template<class T> 
  26. class C { 
  27.     T c; 
  28. }; 
  29.  
  30. template<class T> 
  31. class A { 
  32.     typedef int    Atype; 
  33.     typedef B<Atype>    Btype; 
  34.  
  35.     C<Btype>        c; 
  36. }; 
  37.  
  38.  
  39. #endif 
  40.  
  41. -------------------------------- 
  42. file a.C: 
  43.  
  44. #include "a.h" 
  45.  
  46. A<int>    a; 
  47.  
  48. --------------------------------------- 
  49. The compiler (HP or Sun) complains: 
  50.  
  51.     CC: "t3.h", line 11: error: template class B not yet instantiated;
  52. please add an explicit     instantiation ( typedef B< types>) 
  53.  
  54. g++ works OK. 
  55.  
  56. Thanks, 
  57.  
  58. Rick 
  59.  
  60. BTW, Please don't tell me to get rid of the Atype typedef and replace
  61. Atype with int.  I know that works(!).  This is just an example to
  62. demonstrate the problem. 
  63.  
  64.